<?php

namespace App\Entity\Banner;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use App\Repository\Banner\BannerActionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass=BannerActionRepository::class)
 */
class BannerAction
{
    /**
     * @Common(cnName="#",listType="text",editType="text")
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"banner"})
     */
    private $id;

    /**
     * @Common(cnName="动作描述",listType="text",editType="text",width="")
     * @ORM\Column(type="string", length=255)
     * @Groups({"banner"})
     */
    private $name;

    /**
     * @Common(cnName="标识代码",listType="text",editType="text",width="200")
     * @ORM\Column(type="string", length=255)
     * @Groups({"banner"})
     */
    private $code;

    /**
     * @Common(cnName="参数",listType="text",editType="arrayText")
     * @ORM\Column(type="array")
     * @Groups({"banner"})
     */
    private $params = [];

    /**
     * @Common(cnName="备注",listType="text",editType="text")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"banner"})
     */
    private $tips;

    /**
     * @ORM\OneToMany(targetEntity=Banners::class, mappedBy="action")
     * @Groups({"banners"})
     */
    private $banners;

    public function __construct()
    {
        $this->banners = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getCode(): ?string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

    public function getParams(): ?array
    {
        return $this->params;
    }

    public function setParams(array $params): self
    {
        $this->params = $params;

        return $this;
    }

    public function getTips(): ?string
    {
        return $this->tips;
    }

    public function setTips(?string $tips): self
    {
        $this->tips = $tips;

        return $this;
    }

    /**
     * @return Collection|Banners[]
     */
    public function getBanners(): Collection
    {
        return $this->banners;
    }

    public function addBanner(Banners $banner): self
    {
        if (!$this->banners->contains($banner)) {
            $this->banners[] = $banner;
            $banner->setAction($this);
        }

        return $this;
    }

    public function removeBanner(Banners $banner): self
    {
        if ($this->banners->contains($banner)) {
            $this->banners->removeElement($banner);
            // set the owning side to null (unless already changed)
            if ($banner->getAction() === $this) {
                $banner->setAction(null);
            }
        }

        return $this;
    }
}
